package jUnitTestSuite;

import org.junit.Before;
import org.junit.Test;
import junit.framework.TestCase;

public class ShoppingCartTestCase extends TestCase
{
	private ShoppingCart cart;
	private Product book1, book2, book3;
	
	// set up the test fixture
	@Before
	protected void setUp()
	{
		cart = new ShoppingCart( 2 );
		book1 = new Product( "Robinson Crusoe", 29.96 );
		book2 = new Product( "Lord of the Rings", 30.00);
		book3 = new Product( "Catcher in the Rye", 10.00);
		
		cart.addItem(book1);
		cart.addItem(book2);
	}
	@Test
	protected void tearDown()
	{
		//tear down test fixture if necessary
	}
	
	@Test
	public void testAddTooManyItems()
	{
		// since this is too many items for the cart,
		// this method should return false
		assertEquals( false, cart.addItem(book3) );
	}
	@Test
	public void testRemoveItem()
	{
		// book 1 is in index 0, so test that
		// when we remove index 0 we get correct object
		assertEquals( book1, cart.removeItem(0));
	}
	@Test
	public void testGetTotalCost()
	{
		// the total cost is $59.96
		assertEquals( 59.96, cart.returnCost() );
	}
	@Test
	public void testIncreaseItemPriceToChangeTotalCost()
	{
		// remove book costing 29.96,
		// add 100 to book3 => 100 + 10 = 110
		// total cost should be $140
		cart.removeItem(0);
		book3.increasePrice(100.00);
		cart.addItem(book3);
		
		assertEquals( 140.00, cart.returnCost() );
	}

	// main method
	public static void main( String args[] )
	{
		// run the test
		junit.textui.TestRunner.run( ShoppingCartTestCase.class );
		
	}
}
